<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<div id="app">
    <h1>用户登录</h1>
    <br>
    用户名：<input type="text" v-model="username" placeholder="请输入用户名">
    <br>
    <br>
    密码：<input type="password" v-model="password" placeholder="请输入密码">
    <br>
    <div v-if="message" style="color: red">{{message}}</div>
    <br>
    <button @click="login()">登录</button>
</div>


<script type="application/javascript" src="../js/vue.js"></script>
<script type="application/javascript" src="../js/axios.js"></script>

<script>
    let app = new Vue({
        el:"#app",
        data:{
            username:'',
            password:'',
            message:''
        },
        methods:{
            login:function () {
                app.message='';
                axios.post("../login",{
                    username: app.username,
                    password: app.password
                }).then(function (resp) {
                    let body = resp.data;
                    if (body.success){
                        window.location.href="../article.html";
                    }else {
                        app.message=body.message
                    }
                })
            }
        }
    })
</script>
</body>
</html>